<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      canvas {
        background-color: rgba(255, 0, 0, 0.1);
      }
    </style>
  </head>
  <body>
    <canvas id="tutorial" width="300px" height="300px">
      浏览器不兼容canvas
    </canvas>
    <script>
      window.onload = function () {
        // 1.拿到canvas的元素对象
        let canvasEl = document.getElementById("tutorial");

        if (!canvasEl.getContext("2d")) {
          return;
        }
        // 2.拿到canvas渲染的上下文
        let ctx = canvasEl.getContext("2d"); //2d

        ctx.lineWidth = 10;
        ctx.lineCap = "butt"; // 默认
        // ctx.lineJoin = "miter"; //默认 尖角
        // ctx.lineJoin = "round"; //圆角
        ctx.lineJoin = "bevel";
        // 1.创建一个新的路径
        ctx.beginPath();
        ctx.moveTo(0, 0);
        ctx.lineTo(100, 100);
        ctx.lineTo(200, 0);
        ctx.stroke();
      };
    </script>
  </body>
</html>
